package com.yu.controller.interceptor;

import cn.hutool.core.util.StrUtil;
import com.yu.controller.Code;
import com.yu.exception.BusinessException;
import com.yu.service.AdmainService;
import com.yu.service.StuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class JwtInterceptor implements HandlerInterceptor {
    @Autowired
    private AdmainService admainService;
    @Autowired
    private StuInfoService stuInfoService;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token=request.getHeader("token");
        // 如果不是映射到方法直接通过
        if(!(handler instanceof HandlerMethod)){
            return true;
        }

        //判断token是否为空
        if (StrUtil.isBlank(token)) {
            throw new BusinessException(Code.BUSINESS_ERR,"非法操作,您还没有登录");
        }

        return true;
    }
}
